import { ParamsType } from "@/api/system/device/types";
import request from "@/utils/request";
const currentSystem = localStorage.getItem("usertypeName");

/**
 * 获取设备信息列表
 */
export function getDeviceList(data: ParamsType) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/checkindevice/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/checkindevice/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/checkindevice/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/checkindevice/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/checkindevice/page`;
      break;
    default:
      url = `/api/v1/sysuser/checkindevice/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取设备信息
 */
export function getDeviceInfo(id: number) {
  return request({
    url: `api/v1/device/${id}/form`,
    method: "get",
  });
}

/**
 * 新增设备信息
 */
export function addDevice(data: any) {
  return request({
    url: "/api/v1/sysuser/checkindevice/create",
    method: "post",
    data: data,
  });
}

/**
 * 修改设备信息
 */
export function editDevice(id: number, data: any) {
  return request({
    url: "/api/v1/sysuser/checkindevice/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 删除设备信息
 */
export function deleteDevice(id: number) {
  return request({
    url: "/api/v1/sysuser/checkindevice/" + id,
    method: "delete",
  });
}

/**
 * 审核设备信息
 */
export function auditDevice(id: number) {
  return request({
    url: "/api/v1/sysuser/checkindevice/audit/" + id,
    method: "put",
  });
}

/**
 * 禁用设备信息
 */
export function disableDevice(id: number, data: any) {
  return request({
    url: "/api/v1/sysuser/checkindevice/disable/" + id,
    method: "put",
    params: { disableReason: data },
  });
}

/**
 * 启用设备信息
 */
export function enableDevice(id: number) {
  return request({
    url: "/api/v1/sysuser/checkindevice/enable/" + id,
    method: "put",
  });
}

/**
 * 获取考勤设备信息列表
 */
export function getCheckInDeviceList(data: ParamsType) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/checkindevice/page`;
      break;
    case "Corp":
      url = `/api/v1/corp/checkindevice/page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/checkindevice/page`;
      break;
    case "Manager":
      url = `/api/v1/manager/checkindevice/page`;
      break;
    case "Commander":
      url = `/api/v1/commander/checkindevice/page`;
      break;
    default:
      url = `/api/v1/sysuser/checkindevice/page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取考勤设备信息
 */
export function getCheckInDeviceInfo(id: number) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/checkindevice/${id}/form`;
      break;
    case "Corp":
      url = `/api/v1/corp/checkindevice/${id}/form`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/checkindevice/${id}/form`;
      break;
    case "Manager":
      url = `/api/v1/manager/checkindevice/${id}/form`;
      break;
    case "Commander":
      url = `/api/v1/commander/checkindevice/${id}/form`;
      break;
    default:
      url = `/api/v1/sysuser/checkindevice/${id}/form`;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 新增考勤设备信息
 */
export function addCheckInDevice(data: any) {
  return request({
    url: "/api/v1/sysuser/checkindevice/create",
    method: "post",
    data: data,
  });
}

/**
 * 修改考勤设备信息
 */
export function editCheckInDevice(id: number, data: any) {
  return request({
    url: "/api/v1/sysuser/checkindevice/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 删除考勤设备
 */
export function deleteCheckInDevice(id: number) {
  return request({
    url: "/api/v1/sysuser/checkindevice/" + id,
    method: "delete",
  });
}

/**
 * 禁用考勤设备
 */
export function disableCheckInDevice(id: number) {
  return request({
    url: "/api/v1/sysuser/checkindevice/disable/" + id,
    method: "put",
  });
}

/**
 * 启用考勤设备
 */
export function enableCheckInDevice(id: number) {
  return request({
    url: "/api/v1/sysuser/checkindevice/enable/" + id,
    method: "put",
  });
}

/**
 * 延长考勤设备时限
 */
export function upenddateCheckInDevice(id: number, endDate: Date) {
  return request({
    url: "/api/v1/sysuser/checkindevice/upenddate/" + id,
    method: "put",
    params: { endDate },
  });
}

/**
 * 获取考勤设备下发命令列表
 */
export function getCheckInDeviceCommandList(data: ParamsType) {
  return request({
    url: "/api/v1/sysuser/checkindeviceCommand/page",
    method: "get",
    params: data,
  });
}

/**
 * 获取考勤设备下发命令信息
 */
export function getCheckInDeviceCommandInfo(id: number) {
  return request({
    url: `api/v1/sysuser/checkinDeviceCommand/${id}/form`,
    method: "get",
  });
}

/**
 * 批量下发命令
 */
export function issueCommand(ids: string, codes: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/checkindevice/issuecommand`;
      break;
    case "Corp":
      url = `/api/v1/corp/checkindevice/issuecommand`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/checkindevice/issuecommand`;
      break;
    case "Manager":
      url = `/api/v1/manager/checkindevice/issuecommand`;
      break;
    case "Commander":
      url = `/api/v1/commander/checkindevice/issuecommand`;
      break;
    default:
      url = `/api/v1/sysuser/checkindevice/issuecommand`;
  }
  return request({
    url: url,
    method: "post",
    params: { ids, codes },
  });
}

/**
 * 下发命令记录
 */
export function issueCommandLogPage(data: ParamsType) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = `/api/v1/sysuser/checkindevice/log_page`;
      break;
    case "Corp":
      url = `/api/v1/corp/checkindevice/log_page`;
      break;
    case "Constructor":
      url = `/api/v1/constructor/checkindevice/log_page`;
      break;
    case "Manager":
      url = `/api/v1/manager/checkindevice/log_page`;
      break;
    case "Commander":
      url = `/api/v1/commander/checkindevice/log_page`;
      break;
    default:
      url = `/api/v1/sysuser/checkindevice/log_page`;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 新增考勤设备下发命令信息
 */
export function addCheckInDeviceCommand(data: any) {
  return request({
    url: "/api/v1/sysuser/checkindeviceCommand/create",
    method: "post",
    data: data,
  });
}

/**
 * 修改考勤设备下发命令信息
 */
export function editCheckInDeviceCommand(id: number, data: any) {
  return request({
    url: "/api/v1/sysuser/checkindeviceCommand/" + id,
    method: "put",
    data: data,
  });
}

/**
 * 删除考勤设备下发命令
 */
export function deleteCheckInDeviceCommand(id: number) {
  return request({
    url: "/api/v1/checkindeviceCommand/" + id,
    method: "delete",
  });
}

/**
 * 禁用考勤设备下发命令
 */
export function disableCheckInDeviceCommand(id: number) {
  return request({
    url: "/api/v1/sysuser/checkindeviceCommand/disable/" + id,
    method: "put",
  });
}

/**
 * 启用考勤设备下发命令
 */
export function enableCheckInDeviceCommand(id: number) {
  return request({
    url: "/api/v1/sysuser/checkindeviceCommand/enable/" + id,
    method: "put",
  });
}
